//
//  RegisterViewController.swift
//  IDPNativeApp

//  Created by 九州云腾 on 16/11/11.
//  Copyright © 2016年 九州云腾. All rights reserved.
//

import UIKit
import Alamofire
class RegisterViewController: UIViewController {
    var serverIp = String()
    @IBOutlet weak var usernameTextField: UITextField!
    
    @IBOutlet weak var passwordTextfield: UITextField!
    
    @IBOutlet weak var passwordConfirmTextfield: UITextField!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    @IBAction func register(_ sender: Any) {
        
//        self.usernameTextField.text = "michael";
//        self.passwordTextfield.text = "12345678"
//        self.passwordConfirmTextfield.text = "12345678"
        
//        if self.usernameTextField.text?.characters.count == 0
//            || self.passwordTextfield.text?.characters.count == 0
//            || self.passwordConfirmTextfield.text?.characters.count == 0 {
//            Global.showAlertViewWithController(self, title: "失败", and: "用户名和密码信息不能为空", callback: nil);
//            return;
//        }
//        
//        if self.passwordTextfield.text != self.passwordConfirmTextfield.text {
//            Global.showAlertViewWithController(self, title: "失败", and: "两次密码输入不一致", callback: nil);
//            return;
//        }
//        
//        // 注册用户
//        var parameters = Dictionary<String, Any>()
//        parameters = [
//                      "username": self.usernameTextField.text! as String,
//                      "password": self.passwordTextfield.text! as String,
//                      ]
//        request("\(self.serverIp)\(REGISTER_OIDC)", method: HTTPMethod(rawValue: "POST")!, parameters: parameters, encoding: JSONEncoding.default, headers: nil).validate().responseJSON { (response) in
//
//            switch response.result{
//            case .success:
//                
//                if let j = response.result.value as? Dictionary<String, Any>, let errorNum = j["errorNum"] as? NSNumber {
//            
//                    if errorNum == 0{
//                    self.dismiss(animated: true, completion: {
//                        ToastView.showToast(inParentView: UIApplication.topViewController()!.view, withText: "注册成功！", withDuaration: 4.0)
//                    });
//                    }else if errorNum == 103 {
//                    
//                        Global.showAlertViewWithController(self, title: "注册失败", and: "用户名已经被注册", callback: nil)
//                        
//                    }
//                    
//                }
//                
//            case .failure(let error):
//                print(error)
//                // 如果请求超时
//                if error._code == URLError.timedOut.rawValue {
//                    
//                   Global.showAlertViewWithController(self, title: "注册失败", and: "请求超时", callback: nil)
//                    // 如果没有网络
//                } else if error._code == URLError.notConnectedToInternet.rawValue {
//                  
//                     Global.showAlertViewWithController(self, title: "注册失败", and: "请检查网络", callback: nil)
//                }
//                else{
//                
//                    Global.showAlertViewWithController(self, title: "注册失败", and: "服务器访问错误", callback: nil)
//                }
//                
//                
//            }
//            
//            
//        }
//        

    }
    
    @IBAction func cancel(_ sender: Any) {
        self.dismiss(animated: true, completion: nil);
    }
    
    
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
